<!-- 树用户管理 -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="display: flex;justify-content: space-between;align-items: center;padding: 0 15px;">
			<div>
				<p class="text">树用户管理</p>
			</div>
			<el-form :inline="true" :model="filters" style="margin-top: 12px;">
				<el-form-item>
					<el-input v-model="filters.text" placeholder="请输入手机号"></el-input>
				</el-form-item>
				<el-form-item >
					<el-button type="primary" icon="el-icon-search" v-on:click="getList()">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="List" highlight-current-row v-loading="loading" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column prop="id" align="center" label="ID" width="80"></el-table-column>
			<el-table-column prop="realName" align="center" label="姓名"></el-table-column>
			<el-table-column prop="phone" align="center" label="手机号"></el-table-column>
			<el-table-column prop="treeCount" align="center" label="树的总量" width="180"></el-table-column>
			<el-table-column label="操作" width="200">
				<template slot-scope="scope">
					<el-button type="primary" size="small" @click="LookUser(scope.$index, scope.row)" icon="el-icon-delete">查看用户</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;"></el-pagination>
		</el-col>
		<!-- 分段显示 -->
		<el-dialog title="用户详情" :visible.sync="AccountVisible" width="73%" :before-close="handleClose">
			<el-table :data="AccountList" highlight-current-row v-loading="loading" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
				<el-table-column prop="treeId" align="center" label="ID"></el-table-column>
				<el-table-column prop="treeName" align="center" label="树名称"></el-table-column>
				<el-table-column prop="treeCount" align="center" label="树总量"></el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click.native="AccountVisible = false">取消</el-button>
			</div>
		</el-dialog>
	</section>
</template>
<script>
	import {
		getUserTreeList,
		getUserTreedetail,
		Refreshtoken
	} from '../../../api/api';
	
	export default {
		data() {
			return {
				filters: {
					text: ''
				},
				loading: false,
				List: [],
				sels: [],//列表选中列81560
				total: 0,
				page: 1,
				size:10,
				status:0,
				timer: null,
				AccountVisible:false,
				AccountList:[]
			}
		},
		mounted() {
			this.TreeList()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
		},
		methods: {
			//获取列表
			TreeList:function(type){
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp};
				this.loading = true;
				getUserTreeList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.List = res.data.list;
						this.loading = false;
					}
				});
			},
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			//通过手机号查询
			getList(){
				if(this.filters.text == ''){
					this.$message({
						message: '请输入查询条件',
						type: 'error'
					});
				}else{
					var Token = sessionStorage.getItem('Token');
					var timestamp = new Date().getTime();
					var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp,phone:this.filters.text};
					this.loading = true;
					getUserTreeList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.total = res.data.total;
							this.List = res.data.list;
							this.loading = false;
						}
					});
				}
			},
			// 查看用户
			LookUser(index, row){
				this.AccountVisible = true
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				var para = {token: Token,timestamp: timestamp,userId:row.userId,curpage:this.page,pagesize:this.size};
				getUserTreedetail(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.AccountList = res.data;
						this.loading = false;
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			cellStyle({row, column}){
				return 'text-align:center;padding:5px;';
			},
			rowClass({row, column}){
				return 'text-align:center';
			},
			handleSizeChange(val) {
				this.size = val;
				this.TreeList();
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.TreeList();
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
				    .then(_ => {
						done();
					})
				.catch(_ => {});
			}
		},
		
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.el-select .el-input .el-input--suffix .el-input__inner {
    width: 130px !important;
  }  
</style>


